<?php
require_once(dirname(__FILE__)."/../include/db_mysql.php");

function insert_partyfacility( $partyid, $facilityid )
{
	$sql = new SqlClass;
	//连接数据库
	$sql->connect();
	//执行sql语句

	//先检验partyfacility表中是否已经存在该记录。
	$sql_command = "SELECT * FROM `partyfacility` where partyId='$partyid' and facilityId='$facilityid' ;";

	$r = $sql->exec_sql( $sql_command );
	$row = mysql_fetch_array($r);

	if( $row != '' )  //说明partyfacility表已存在该记录
	{
		$sql->close();
		return true;
	}

	//说明partyfacility表中没有该记录，则新插入一条。
	$sql_command = "INSERT INTO  `partyfacility` (
					partyId ,
					facilityId
					)
					VALUES (
					'$partyid',  '$facilityid'
					);";
	$r = $sql->exec_sql( $sql_command );//保存执行sql的结果

    if( mysql_error() )//刚才插入失败
	{
		$sql->close();
		return '';
	}

	$sql->close();
	return true;

}

/*function test( $a, $b)
{
	$sql = new SqlClass;
	//连接数据库
	$sql->connect();
	//执行sql语句

	//先检验partyfacility表中是否已经存在该记录。
	$sql_command = "SELECT * FROM `zzz` where aaa='$a' and bbb='$b' ;";

	$r = $sql->exec_sql( $sql_command );
	$row = mysql_fetch_array($r);

	if( $row != '' )  //说明partyfacility表已存在该记录
	{
		$sql->close();
		return true;
	}

	//说明partyfacility表中没有该记录，则新插入一条。
	$sql_command = "INSERT INTO  `zzz` (
					aaa,
					bbb
					)
					VALUES (
					'$a',
				    '$b'
					);";
	$r = $sql->exec_sql( $sql_command );//保存执行sql的结果

	$partyId = mysql_insert_id();//得到刚才插入的记录Id。
	error_log( $partyId, 3, "./test_insert_partyfacility.log.log");
    if( $partyId == 0 ) //说明partyId出错
	{
		$sql->close();
		return false;
	}

	$sql->close();
	return true;
}*/
?>